<%@ page import="java.io.ByteArrayOutputStream" %>
<%@ page import="java.io.PrintStream" %>
<%@ page import="org.apache.commons.lang.StringUtils" %>
<%@ page language="java" contentType="text/html;charset=UTF-8" pageEncoding="UTF-8"%>
<%@page isErrorPage="true" %>
<%
    //response.setStatus(HttpServletResponse.SC_OK);
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>

    <title>出错咯!</title>

    <meta http-equiv="pragma" content="no-cache">
    <meta http-equiv="cache-control" content="no-cache">
    <meta http-equiv="expires" content="0">
    <meta http-equiv="description" content="This is err page">
    <!--
     <link rel="stylesheet" type="text/css" href="styles.css">
     -->

<script type="text/javascript">
    <%
    String mes="";
    if (exception!=null){
     String mess = exception.getMessage();
     if (mes!=null && StringUtils.contains(mess,"org.apache.shiro.session.UnknownSessionException")){
       mes="unknownSessionErr";
     }
    }

    %>
    var errm="<%=mes%>";
            window.onload=function(){
                if (errm=="unknownSessionErr"){
                    document.getElementById("unknowSession").style.display='block';
                    document.getElementById("commmessage").style.display='none';
                    top.location="<%=request.getContextPath()%>"+"/index.html";
                }
            }

    function showErr(){
        var showdom=document.getElementById("errorMessageDiv");
        if (showdom.style.display=='none'){
            showdom.style.display='block';
        }else {
            showdom.style.display='none';
        }
    }
</script>
</head>

<body>
<br><br><br>
<div id="unknowSession" style="color: red;display: none">登陆已过期或者密码错误!正在转到登陆页面....</div>
<table id="commmessage" width="100%">
    <tr>
        <td style="border-bottom:dotted 1px Gray;color: red"  >
            &nbsp;&nbsp;错误提示:<%=response.getStatus()%>
        </td>
    </tr>
    <tr>

        <td style="color: black">尊敬的用户：<br />系统出现了异常，请重试。
            <br />如果问题重复出现，请向系统管理员反馈。<br /><br />
            <a id="showErrorMessageButton" href="javascript:showErr();">详细错误信息</a>
        </td>
    </tr>
</table>
<div id="errorMessageDiv" style="display: none">
            <pre>
                <%
                    try {
                        if (exception!=null) {
                            //全部内容先写到内存，然后分别从两个输出流再输出到页面和文件
                            ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
                            PrintStream printStream = new PrintStream(byteArrayOutputStream);
                            printStream.println(exception.getClass() + " : " + exception.getMessage());
                            printStream.println();
                            printStream.println("堆栈信息");
                            exception.printStackTrace(printStream);
                            printStream.println();
                            out.print(byteArrayOutputStream);    //输出到网页

                        }
                    } catch (Exception ex) {
                        ex.printStackTrace();
                    }
                %>
            </pre>
</div>
</body>
</html>
